<?php
/*
	我的下线
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
set_html('title','我的团');
if($_RQ['op']=='main'){
	$member=$this->model('member')->checkmember();
	$return['setting']=$this->plugin_setting('page');
	set_html('tabs',$return['setting']['agent_tagent']?:'我的团');
	$setting=$this->plugin_setting('setting');
	$levelnum=3;
	$agent_ids=$_SESSION['uid'];
	$agent_num=$this->count('member',array('merchid'=>$_SESSION['onemerchid'],'fromuser'=>$_SESSION['uid']),array('mid'),'mid');
	$return['agent_num']=$agent_num;
	$return['member']=$member;
	$return['params']=array('page'=>1);
	$return['psize']=20;
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$params['fromuser']=$_SESSION['uid'];
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
	);
	if($_SESSION['onemerchid']){
		$params['merchid']=$_SESSION['onemerchid'];
		$params['fields']=array('id','nickname','avatar','mid','createtime');
		$list=pdo_getlist('jy_merch_member',$parameter);
	}else{
		$list=pdo_getlist('core_members',$parameter);
		$params['fields']=array('id','nickname','avatar','createtime');
	}
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		if(!$_SESSION['onemerchid']){
			$item['mid']=$item['id'];
		}
		$item['member']=cfc('core')->member_show($item['mid']);
		$item['ordercount']=$this->count('order',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid']));
		$item['moneycount']=$this->getsum('order',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid']),'order_price');
	}
	exi($list);
}
?>